<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>邮件发送</title>
    <link rel="stylesheet" href="/css/font.css">
    <link rel="stylesheet" href="/css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script src="/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/js/xadmin.js"></script>
</head>
<body>
<form class="layui-form" style="position: absolute; top:5%">
    <div class="layui-form-item" >
        <label class="layui-form-label">收件人</label>
        <div class="layui-input-inline">
            <input type="text" th:value ="${user.userEmail}" name="email" id="email" lay-verify="email"  autocomplete="off" class="layui-input">
    </div>
    </div>
    <div class="layui-form-item layui-form-text" style="width: 900px;">
        <label class="layui-form-label">邮件内容</label>
        <div class="layui-input-block">
            <textarea name="emailText" id="emailText" rows="25" placeholder="请输入内容" class="layui-textarea"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn" lay-submit lay-filter="sendCode">发送</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            <span id="e" style="color: red"></span>
        </div>
    </div>
</form>
</body>
</html>
<script>
    $(function  () {
        layui.use('form', function(){
            var form = layui.form;
            //发送验证码
            form.on('submit(sendCode)', function(data){
                //验证邮箱验证码不能为空
                if(data.field.email==""){
                    layer.alert("邮箱不能为空");
                    return false;
                }else if(data.field.emailText=="")
                {
                    layer.alert("邮件内容不能为空");
                    return false;
                }
                //发送 ajax请求
                $.ajax({
                    url:"/manager/sendEmailAjax",
                    type:"post",
                    data:data.field,
                    dataType:"json",//返回的数据类型
                    success:function (data) {
                        //定义{info:"登录成功"}
                        $("#e").text(data.info);
                    }
                })
                return false;
            });
        });
    })
</script>